
import numpy as np
from view.endSrc.One2OneDistance import One2OneDistance

class NodeSet:
    def __init__(self, dataset:list, idList: list):
        self.dataset = dataset
        self.idList = idList
        self.dim = len(self.dataset[0])

        print(self.idList, type(self.idList))
    def _getMean(self):
        m = np.zeros(self.dim)
        for i in self.idList:
            m = self.dataset[i] + m
        mean = m/len(self.idList)
        return mean


    def distance(self, other):
        m1 = self._getMean()
        m2 = other._getMean()
        p2p = One2OneDistance()
        dis = p2p(m1, m2)
        return dis


    def merge(self, other):
        node = NodeSet(self.dataset, self.idList)
        for i in other.idList:
            node.idList.append(i)
        return node

    def __str__(self):

        tmp = '['
        for i in self.idList:
            tmp += str(i) + ', '

        tmp += ']'
        return tmp






